package com.cyq.day04.HomeWork;

import java.util.Scanner;

public class HomeWork01 {
    public static void main(String[] args) {
        HomeWork01();
        HomeWork02();
        HomeWork03();
        HomeWork04();
    }

    public static void HomeWork01() {
        //1.输出1000以内的所有质数
        for (int i = 0; i <= 1000; i++) {
            int num = i;
            int j = 2;
            for (; j < num; j++) {
                if (num % j == 0) {
                    break;
                }
            }
            if (num == j) {
                System.out.println("1:" + num + "是质数");
            }
        }
    }

    public static void HomeWork02() {
        //2. 2/1，3/2，5/3，8/5，13/8，21/13，求前20项的和
        double sum = 0;
        int x = 2;
        int y = 1;
        for (int i = 1, t; i <= 20; i++) {
            sum += (double) x / y;
            t = y;
            y = x;
            x = y + t;
        }
        System.out.println("2:" + "前20项的和为" + sum);
    }

    public static void HomeWork03() {
        //3.输入一个正整数，要求把该数反序输出543-345
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个正整数");
        int num = sc.nextInt();
        int a = 0;
        System.out.print("3." + "反序输出的结果为:");
        while (num != 0) {
            a = a * 10 + num % 10;
            num = num / 10;
        }
        System.out.println(a);
    }

    public static void HomeWork04() {
        //4.打印菱形（9行）
        for (int i = 0; i <= 5; i++) {
            for (int a = 1; a <= 5 - i; a++) {
                System.out.print(" ");
            }
            for (int b = 1; b <= 2 * i - 1; b++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (int j = 0; j <= 4; j++) {
            for (int a = 1; a <= j; a++) {
                System.out.print(" ");
            }
            for (int b = 7; b >= 2 * j - 1; b--) {
                System.out.print("*");
            }
            System.out.println();
        }

    }
}
